// 处理用户登录逻辑
const db = require("../lib/db")

function userLogin(username,userpwd){
    console.log(username,userpwd)
    return new Promise((resolve,reject)=>{
        let sql = "select * from login where userName = '"+username+"'";
        console.log(sql)
        db.querySql(sql).then(data=>{
            console.log(data)
            if(data.length == 0){
                resolve(501)
            }else{
                if(data[0].userPassword == userpwd){
                    resolve(data[0])
                    console.log("登陆成功")
                }else{
                    resolve(502)
                    console.log("密码错误")
                }
            }
        })
    })
    
}

// 导出
module.exports = userLogin;